$(".btnb").click(function(){
  location.href="查看详情列表.html"
})

var pid1=`http://jx.xuzhixiang.top/ap/api/detail.php`
var obj=new URLSearchParams(location.search)
var pid=obj.get("pid")
axios.get(pid1,{params:{id:pid},}).then((res)=>{
  var {data}=res;
  var pObj=data.data
  var html=`
  <li class="a11">
     <img class="a110" src="${pObj.pimg}">
     <h3>${pObj.pname}</h3>
    <p>$${pObj.pprice}</p>
    </li>
  `
  var item=document.querySelector("#qq")
  console.log(item)
  item.innerHTML=html

})

// 展示购物车

a1()
async function a1(){
  var uid=localStorage.getItem("id")
  var {data}=await axios.get(
    `http://jx.xuzhixiang.top/ap/api/cart-list.php`,{params:{id:uid}}
  )

  var res=""
  data.data.forEach((v)=>{
   res+= `
    <li class="a11" style="float: left; margin: 0 5px;">
      <img class="a110" src="${v.pimg}">
      <h3>${v.pname}</h3>
      <p>$${v.pprice}</p>
      <button class="shanchu"  onclick=del(${v.pid},this)>X</button>
      </li> 
    ` 
  })
 
  console.log(res);
    var list=document.querySelector("#qq")
    list.innerHTML=res
}   
// 删除
    async function del(pid,btn){
      console.log(pid)
      var uid=localStorage.getItem("id")
    var{data}=await axios.get(`http://jx.xuzhixiang.top/ap/api/cart-delete.php`,{params:{uid,pid}})
    console.log(data)
      // 删除父元素
    btn.parentNode.remove()
    }

  // 金钱

a2()
async function a2(){
  var uid=localStorage.getItem("id")
  var {data}=await axios.get(
    "http://jx.xuzhixiang.top/ap/api/cart-list.php",{params:{id:uid}}
  )
  
  var res=data.data.map((v)=>`
  <li class="a01" style="  float: left;">
  <p class="jiage">${v.pprice}</p>  
  </li>  
  `
  ) 
  
   console.log(data.data)
  
    console.log(parseInt(data.data[0].pprice)
      )


    var list=document.querySelector("h1");
    list.innerHTML= res 
     let p=document.querySelectorAll(".jiage");
     let num=0;
     p.forEach((item)=>{
       let j=parseInt(item.innerHTML);
       num+=j;
     })
     list.innerHTML=num;



//  结算
var jiesuan=document.querySelector(".jiesuan ")

jiesuan.onclick=function(){
  alert("小伙子，您本次消费"+num+"元")
  location.href="付款码.html"

}
  }



